package com.company.iterator.v06;


class MyArrayList implements Collection_, Iterator {
    Object[] objects = new Object[10];
    private int index = 0;

    public void add(Object o) {
        if (index == objects.length) {
            Object[] newObjects = new Object[objects.length + 2];
            System.arraycopy(objects, 0, newObjects, 0, objects.length);
            objects = newObjects;
        }
        objects[index] = o;
        index++;
    }


    public int size() {
        return index;
    }

    @Override
    public Iterator iterator() {
        return new ArrayListIterator();
    }

    @Override
    public boolean hasNext() {
        return false;
    }

    @Override
    public Object next() {
        return null;
    }


    class ArrayListIterator implements Iterator {
        private int correntIndex = 0;

        @Override
        public boolean hasNext() {
            if (correntIndex >= index) {
                return false;
            }
            return true;
        }

        @Override
        public Object next() {
            Object o = objects[correntIndex];
            correntIndex++;

            return o;
        }
    }
}

